# FROM openjdk:8-oraclelinux7
FROM centos:7

# centos 7 换镜像源
RUN sed -i "s/#baseurl/baseurl/g" /etc/yum.repos.d/CentOS-Base.repo; \
    sed -i "s/mirrorlist=http/#mirrorlist=http/g" /etc/yum.repos.d/CentOS-Base.repo; \
    sed -i "s@http://mirror.centos.org@https://repo.huaweicloud.com@g" /etc/yum.repos.d/CentOS-Base.repo; \
    yum clean all -y; \
    yum makecache;

# centos 7 安装 java
RUN yum install -y java-1.8.0-openjdk gettext nmap-ncat openssl busybox-extras curl unzip

# 通用安装包
# RUN yum install -y gettext nmap-ncat openssl busybox-extras curl unzip

ARG user=rocketmq
ARG group=rocketmq
ARG uid=3000
ARG gid=3000

RUN groupadd -g ${gid} ${group} \
    && useradd -u ${uid} -g ${gid} -m -s /bin/bash ${user}

ARG version=4.8.0

ENV ROCKETMQ_VERSION ${version}

ENV ROCKETMQ_HOME  /home/rocketmq/rocketmq-${ROCKETMQ_VERSION}

WORKDIR  ${ROCKETMQ_HOME}

RUN set -eux; \
    curl -L https://repo.huaweicloud.com/apache/rocketmq/${ROCKETMQ_VERSION}/rocketmq-all-${ROCKETMQ_VERSION}-bin-release.zip -o rocketmq.zip; \
    unzip rocketmq.zip; \
        mv rocketmq-all*/* . ; \
        rmdir rocketmq-all* ; \
        rm rocketmq.zip;

# 编绎并运行控制台
RUN mkdir /home/rocketmq/.m2; \
    mkdir /root/.m2;

COPY  ./settings.xml /home/rocketmq/.m2
COPY  ./settings.xml /root/.m2

RUN yum install -y maven git; \
    git config --global url."https://ghproxy.com/https://github.com".insteadOf "https://github.com"; \
    git clone https://github.com/apache/rocketmq-externals.git; \
    mv rocketmq-externals /home/rocketmq; \
    cd /home/rocketmq/rocketmq-externals/rocketmq-console; \
    mvn clean package -DskipTests; \
    chown ${group}:${user} -R /home/rocketmq/rocketmq-externals/rocketmq-console/*; \
    echo -e "#!/bin/bash\ncd /home/rocketmq/rocketmq-externals/rocketmq-console/target/;\njava -jar rocketmq-console-ng-*.jar --rocketmq.config.namesrvAddr=${HOST}:9876" > ${ROCKETMQ_HOME}/bin/console.sh; \
    chmod +x ${ROCKETMQ_HOME}/bin/console.sh;


RUN chown -R ${uid}:${gid} ${ROCKETMQ_HOME}

EXPOSE 9876

EXPOSE 10909 10911 10912

RUN export JAVA_OPT=" -Duser.home=/opt"

# 修改内存容量
RUN sed -i "s/-Xms4g\ -Xmx4g\ -Xmn2g/-Xms128m\ -Xmx128m\ -Xmn64m/g" ${ROCKETMQ_HOME}/bin/runserver.sh; \
    sed -i "s/-Xms8g\ -Xmx8g\ -Xmn4g/-Xms256m\ -Xmx256m\ -Xmn128m/g" ${ROCKETMQ_HOME}/bin/runbroker.sh;

USER ${user}

RUN mkdir ${ROCKETMQ_HOME}/logs && mkdir ${ROCKETMQ_HOME}/store

WORKDIR ${ROCKETMQ_HOME}/bin
